package com.meituan.catering.management.order.remote.model.converter;

import com.meituan.catering.management.order.remote.model.response.ProductDetailRemoteResponse;
import com.meituan.catering.management.product.api.thrift.model.dto.ProductDetailThriftDTO;
import com.meituan.catering.management.product.api.thrift.model.response.ProductDetailThriftResponse;

import java.util.LinkedList;
import java.util.List;

/**
 * @author Believe
 * Date 2022/5/29 12:44
 */
public class ProductDetailRemoteResponseConverter {
    public static ProductDetailRemoteResponse toProductDetailRemoteResponse(ProductDetailThriftDTO productDetailThriftDTO){
        ProductDetailRemoteResponse productDetailRemoteResponse = new ProductDetailRemoteResponse();
        productDetailRemoteResponse.setId(productDetailThriftDTO.getId());
        productDetailRemoteResponse.setTenantId(productDetailThriftDTO.getTenantId());
        productDetailRemoteResponse.setVersion(productDetailThriftDTO.getVersion());
        productDetailRemoteResponse.setAuditing(productDetailThriftDTO.getAuditing());
        productDetailRemoteResponse.setName(productDetailThriftDTO.getName());
        productDetailRemoteResponse.setUnitPrice(productDetailThriftDTO.getUnitPrice());
        productDetailRemoteResponse.setUnitOfMeasure(productDetailThriftDTO.getUnitOfMeasure());
        productDetailRemoteResponse.setMinSalesQuantity(productDetailThriftDTO.getMinSalesQuantity());
        productDetailRemoteResponse.setIncreaseSalesQuantity(productDetailThriftDTO.getIncreaseSalesQuantity());
        productDetailRemoteResponse.setDescription(productDetailThriftDTO.getDescription());
        productDetailRemoteResponse.setEnabled(productDetailThriftDTO.getEnabled());
        productDetailRemoteResponse.setMethodGroups(toMethodGroup(productDetailThriftDTO.getMethodGroups()));
        productDetailRemoteResponse.setAccessoryGroups(toAccessoryGroup(productDetailThriftDTO.getAccessoryGroups()));
        return productDetailRemoteResponse;
    }



    public static List<ProductDetailRemoteResponse> toProductDetailRemoteResponseList(List<ProductDetailThriftResponse> responses){
        List<ProductDetailRemoteResponse> responseList = new LinkedList<>();
        for (ProductDetailThriftResponse respons : responses) {
            ProductDetailRemoteResponse productDetailRemoteResponse = new ProductDetailRemoteResponse();
            productDetailRemoteResponse.setId(respons.getData().getId());
            productDetailRemoteResponse.setTenantId(respons.getData().getTenantId());
            productDetailRemoteResponse.setVersion(respons.getData().getVersion());
            productDetailRemoteResponse.setAuditing(respons.getData().getAuditing());
            productDetailRemoteResponse.setName(respons.getData().getName());
            productDetailRemoteResponse.setUnitPrice(respons.getData().getUnitPrice());
            productDetailRemoteResponse.setUnitOfMeasure(respons.getData().getUnitOfMeasure());
            productDetailRemoteResponse.setMinSalesQuantity(respons.getData().getMinSalesQuantity());
            productDetailRemoteResponse.setIncreaseSalesQuantity(respons.getData().getIncreaseSalesQuantity());
            productDetailRemoteResponse.setDescription(respons.getData().getDescription());
            productDetailRemoteResponse.setEnabled(respons.getData().getEnabled());
            productDetailRemoteResponse.setMethodGroups(toMethodGroup(respons.getData().getMethodGroups()));
            productDetailRemoteResponse.setAccessoryGroups(toAccessoryGroup(respons.getData().getAccessoryGroups()));
            responseList.add(productDetailRemoteResponse);
        }
        return responseList;
    }
    public static List<ProductDetailRemoteResponse.AccessoryGroup> toAccessoryGroup(List<ProductDetailThriftDTO.AccessoryGroup> accessoryGroups){
        List<ProductDetailRemoteResponse.AccessoryGroup> accessoryGroupList = new LinkedList<>();
        for (ProductDetailThriftDTO.AccessoryGroup accessoryGroup : accessoryGroups) {
            ProductDetailRemoteResponse.AccessoryGroup group = new ProductDetailRemoteResponse.AccessoryGroup();
            group.setName(accessoryGroup.getName());
            group.setOptions(toAccOption(accessoryGroup.getOptions()));
            accessoryGroupList.add(group);
        }
        return accessoryGroupList;
    }

    public static List<ProductDetailRemoteResponse.AccessoryGroup.Option> toAccOption(List<ProductDetailThriftDTO.AccessoryGroup.Option> options){
        List<ProductDetailRemoteResponse.AccessoryGroup.Option> optionList = new LinkedList<>();
        for (ProductDetailThriftDTO.AccessoryGroup.Option option : options) {
            ProductDetailRemoteResponse.AccessoryGroup.Option remote = new ProductDetailRemoteResponse.AccessoryGroup.Option();
            remote.setId(option.getId());
            remote.setName(option.getName());
            remote.setUnitPrice(option.getUnitPrice());
            remote.setUnitOfMeasure(option.getUnitOfMeasure());
            optionList.add(remote);
        }
        return optionList;
    }

    public static List<ProductDetailRemoteResponse.MethodGroup> toMethodGroup(List<ProductDetailThriftDTO.MethodGroup> methodGroups){
        List<ProductDetailRemoteResponse.MethodGroup> methodGroupList = new LinkedList<>();
        for (ProductDetailThriftDTO.MethodGroup methodGroup : methodGroups) {
            ProductDetailRemoteResponse.MethodGroup group = new ProductDetailRemoteResponse.MethodGroup();
            group.setName(methodGroup.getName());
            group.setOptions(toOption(methodGroup.getOptions()));
            methodGroupList.add(group);
        }
        return methodGroupList;
    }

    public static List<ProductDetailRemoteResponse.MethodGroup.Option> toOption(List<ProductDetailThriftDTO.MethodGroup.Option> options){
        List<ProductDetailRemoteResponse.MethodGroup.Option> optionList = new LinkedList<>();
        for (ProductDetailThriftDTO.MethodGroup.Option option : options) {
            ProductDetailRemoteResponse.MethodGroup.Option remote = new ProductDetailRemoteResponse.MethodGroup.Option();
            remote.setId(option.getId());
            remote.setName(option.getName());
            optionList.add(remote);
        }
        return optionList;
    }
}
